package cn.zd.thumbbackend.service.impl;

import cn.zd.thumbbackend.constant.UserConstant;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.zd.thumbbackend.model.entity.User;
import cn.zd.thumbbackend.service.UserService;
import cn.zd.thumbbackend.mapper.UserMapper;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

/**
 * @author zheng
 * @description 针对表【user】的数据库操作Service实现
 * @createDate 2025-05-20 14:44:44
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {
    
    @Override
    public User login(long userId, HttpServletRequest request) {
        User user = baseMapper.selectById(userId);
        request.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, user);
        return user;
    }
    
    @Override
    public User getLoginUser(HttpServletRequest request) {
        return (User) request.getSession().getAttribute(UserConstant.USER_LOGIN_STATE);
    }
    
    
}




